﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace smartphone.App_Code
{
    public static class LinkFactory
    {
        static LinkFactory()
        {

        }

        // Builds an absolute URL
        private static string BuildAbsolute(string relativeUri)
        {
            // get current uri
            Uri uri = HttpContext.Current.Request.Url;
            // build absolute path
            string app = HttpContext.Current.Request.ApplicationPath;
            if (!app.EndsWith("/")) app += "/";
            relativeUri = relativeUri.TrimStart('/');
            // return the absolute path
            return HttpUtility.UrlPathEncode(
              String.Format("http://{0}:{1}{2}{3}",
              uri.Host, uri.Port, app, relativeUri));
        }

        // tao 1 URL hang san xuat
        public static string ToManufacturer(string manufacturerId, string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("Manufacturer_page.aspx?ManufacturerId={0}", manufacturerId));
            else
                return BuildAbsolute(String.Format("Manufacturer_page.aspx?ManufacturerId={0}&Page={1}", manufacturerId, page));
        }

        // Generate a department URL for the first page
        public static string ToManufacturer(string manufacturerId)
        {
            return ToManufacturer(manufacturerId, "1");
        }

        //Build link den chi tiet san pham
        public static string ToProductDetail(string productId)
        {
            return BuildAbsolute(String.Format("Product.aspx?ProductId={0}", productId));
        }

        public static string ToProductImage(string productImg)
        {
            return BuildAbsolute("ProductImages/" + productImg);
        }
    }

}